home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libobj / geom.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  4.1 KB  |  152 lines

  1. /*
  2.  * geom.h
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * geom.h,v 4.1 1994/08/09 07:59:02 explorer Exp
  17.  *
  18.  * geom.h,v
  19.  * Revision 4.1  1994/08/09  07:59:02  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:09  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0.1.1  92/02/07  13:10:58  cek
  26.  * patch6: Decreased MAXMODELDEPTH to keep from beating on the stack.
  27.  * 
  28.  * Revision 4.0  91/07/17  14:37:52  kolb
  29.  * Initial version.
  30.  * 
  31.  */
  32. #ifndef OBJECT_H
  33. #define OBJECT_H
  34.  
  35. #include "libcommon/common.h"
  36. #include "libcommon/transform.h"
  37. #include "bounds.h"
  38.  
  39. /*
  40.  * Constants for enter flag in HitNode.
  41.  */
  42. #define EXITING        1
  43. #define ENTERING    2
  44.  
  45. #define MAXMODELDEPTH    32        /* Maximum height of DAG. */
  46.  
  47. typedef char * GeomRef;
  48. typedef GeomRef GeomCreateFunc();
  49.  
  50. /*
  51.  * If the object has a normal method, it's a primitive
  52.  * otherwise it's an aggregate (or an instance)
  53.  */
  54. #define IsAggregate(o)        ((o)->methods->normal == NULL)
  55.  
  56. /*
  57.  * Geom methods.
  58.  * (p) means applies only to primitive objects
  59.  * (a) means applies only to aggregate objects
  60.  */
  61. typedef struct Methods {
  62.     char        *(*name)();        /* Geom name */
  63.     GeomRef        (*create)();        /* Create and return ref */
  64.     int        (*intersect)(),        /* Ray/obj intersection */
  65.             (*normal)(),        /* Geom normal (p) */
  66.             (*enter)(),        /* Ray enter or exit? (p) */
  67.             (*convert)();        /* Convert from list (a) */
  68.     void        (*uv)(),        /* 2D mapping (p) */
  69.             (*stats)(),        /* Statistics */
  70.             (*bounds)(),        /* Bounding volume */
  71.             (*user)();        /* User-defined method */
  72.     struct Methods    *(*methods)();        /* object methods func. */
  73.     char        checkbounds,        /* check bbox before int.? */
  74.             closed;            /* properly closed? */
  75. } Methods;
  76.  
  77. typedef void (*UserMethodType)();
  78.  
  79. /*
  80.  * Geom definition
  81.  */
  82. typedef struct Geom {
  83.     char *name;            /* Geom name, if any. */
  84.     GeomRef obj;            /* Pointer to object info. */
  85.     Methods *methods;
  86.     unsigned long prims;        /* sum of # primitive objects */
  87.     Float bounds[2][3];        /* Bounding box */
  88.     Float timenow;            /* Geom's idea of what time it is */
  89.     short int animtrans;        /* transformation is animated */
  90.     short int frame;        /* frame for which obj is inited */
  91.     struct Surface *surf;        /* surface, if any */
  92.     struct Trans *trans;        /* Transformation information */
  93.     struct Trans *transtail;    /* Double linked list end */
  94.     struct Texture *texture;    /* Texture mapping info. */
  95. #ifdef SHAREDMEM
  96.     unsigned long *counter;        /* Geoms are shared, counters aren't */
  97. #else
  98.     unsigned long counter;        /* "mailbox" for grid intersection */
  99. #endif
  100.     struct Geom *next;        /* Next object. */
  101. } Geom;
  102.  
  103. /*
  104.  * Linked list of pointers to objects.
  105.  */
  106. typedef struct GeomList {
  107.     Geom *obj;
  108.     struct GeomList *next;
  109. } GeomList;
  110.  
  111. /*
  112.  * Array of hit information.  Stores a path through an object DAG,
  113.  * as well as the ray in 'model' (object) space and the distance from
  114.  * the ray origin to the point of intersection.
  115.  */
  116. typedef struct HitNode {
  117.     Geom *obj;            /* Geom hit */
  118.     Ray    ray;            /* Ray */
  119.     Float    mindist;        /* Amount of ray to ignore */
  120.     Float    dist;            /* Distance from ray origin to hit */
  121.     short    enter,            /* Enter (TRUE) or Leave (FALSE) obj */
  122.         dotrans;        /* transformations non-identity? */
  123.     Trans    trans;            /* parent-->obj and inverse trans */
  124. } HitNode;
  125.  
  126. /*
  127.  * Structure holding a list of HitNodes.  A maximum of MAXMODELDEPTH
  128.  * nodes can be referenced.
  129.  */
  130. typedef struct HitList {
  131.     int nodes;
  132.     HitNode data[MAXMODELDEPTH];
  133. } HitList;
  134.  
  135. extern char    *GeomName();
  136.  
  137. extern Geom    *GeomCreate(), *GeomCopy(), *GeomCopyNamed(),
  138.         *GeomComputeAggregateBounds();
  139.  
  140.  
  141. extern GeomList    *GeomStackPush(), *GeomStackPop();
  142.  
  143. extern void     PrimUV(), AggregatePrintInfo(),
  144.         IntersectStats();
  145.  
  146. extern int    AggregateConvert(), PrimNormal(),
  147.         TraceRay();    /* application-provided */
  148.  
  149. extern Methods    *MethodsCreate();
  150.  
  151. #endif /* OBJECT_H */
  152.